package com.example.audiorecord.adapter;

import android.view.View;
import android.widget.BaseAdapter;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.audiorecord.R;
import com.example.audiorecord.utils.CommonTools;

import org.jetbrains.annotations.NotNull;

import java.io.File;

/**
 * 显示录音文件列表的适配器
 */
public class FileListAdapter extends BaseQuickAdapter<File, BaseViewHolder> {
    private onClickFileListListener onClickFileListListener;

    public void setOnClickFileListListener(FileListAdapter.onClickFileListListener onClickFileListListener) {
        this.onClickFileListListener = onClickFileListListener;
    }

    public FileListAdapter() {
        super(R.layout.adapter_file_list);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, File file) {
        baseViewHolder.setText(R.id.adapter_file_list_name,file.getName());
        baseViewHolder.setText(R.id.adapter_file_list_create_size,CommonTools.FormetFileSize(file.length()));
        baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickFileListListener.onClick(file);
            }
        });
        baseViewHolder.setText(R.id.number_text,String.valueOf(baseViewHolder.getLayoutPosition()+1)+".");
    }

   public interface onClickFileListListener{
        void onClick(File file);
    }
}
